package cn.ject.mcpclient.config;

import cn.ject.mcpclient.service.Assistant;
import dev.langchain4j.mcp.McpToolProvider;
import dev.langchain4j.mcp.client.DefaultMcpClient;
import dev.langchain4j.mcp.client.McpClient;
import dev.langchain4j.mcp.client.transport.McpTransport;
import dev.langchain4j.mcp.client.transport.http.HttpMcpTransport;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.tool.ToolProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author Administrator
 */
@Configuration
@RequiredArgsConstructor
public class AssistantInit {

    final ChatLanguageModel chatLanguageModel;


    McpTransport transport = new HttpMcpTransport.Builder()
            .sseUrl("http://localhost:8080/sse")
            .logRequests(true) // if you want to see the traffic in the log
            .logResponses(true)
            .build();

    McpClient mcpClient = new DefaultMcpClient.Builder()
            .transport(transport)
            .build();


    ToolProvider toolProvider = McpToolProvider.builder()
            .mcpClients(List.of(mcpClient))
            .build();


    @Bean
    public Assistant serviceInit() {
        return AiServices.builder(Assistant.class)
                .toolProvider(toolProvider)
                .chatLanguageModel(chatLanguageModel).build();
    }


}
